package com.rui.common.util;

import com.github.pagehelper.Page;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * 分页工具类
 *
 * @author xr
 * @email xr@qq.com
 * @date 2020-01-01 00:00:00
 */
@Data
public class Pages<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    @ApiModelProperty("当前页")
    private int pageNum;
    @ApiModelProperty("每页的数量")
    private int pageSize;
    @ApiModelProperty("总记录数")
    private long total;
    @ApiModelProperty("分页数据")
    private List<T> result;

    public Pages() {
        super();
    }

    public Pages(List<T> list) {
        if (list instanceof Page) {
            Page<T> page = (Page<T>) list;
            this.pageNum = page.getPageNum();
            this.pageSize = page.getPageSize();
            this.total = page.getTotal();
            this.result = page.getResult();
        } else {
            this.result = list;
        }
    }
}
